package com.jtjrenren.android.taxi.driver.core.wallect;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.jtjrenren.android.taxi.driver.base.BaseRcyAdapter;
import com.jtjrenren.android.taxi.driver.R;
import com.jtjrenren.android.taxi.driver.bean.api.ApiTixian;
import com.library.utils.StringUtils;

/**
 * Created by Administrator on 2016/3/16.
 */
public class TxHistoryAdapter extends BaseRcyAdapter<ApiTixian.RechargeListEntity> {
    public TxHistoryAdapter(Context context) {
        super(context);
    }

    @Override
    public RecyclerView.ViewHolder getItemViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.item_tx_history, parent, false);

        return new TxViewHolder(view);
    }

    @Override
    public void onBindItemViewHolder(RecyclerView.ViewHolder holder, int position) {
        ApiTixian.RechargeListEntity info = list.get(position);
        TxViewHolder txViewHolder = (TxViewHolder) holder;

        int drawableResId = getDrawableResId(Integer.parseInt(info.getTradeType()),
                Integer.parseInt(StringUtils.isEmpty(info.getBankCode()) ? "0" : info.getBankCode()));

        txViewHolder.iv_icon.setImageResource(drawableResId);
        txViewHolder.tv_account.setText(info.getTradeAccount());
        txViewHolder.tv_count.setText(info.getTradeFair());
        txViewHolder.tv_date.setText(info.getTradeTime());
        String typeName = getTypeName(Integer.parseInt(info.getTradeType()));
        txViewHolder.tv_desc.setText("提现到" + typeName);

    }

    public class TxViewHolder extends RecyclerView.ViewHolder {
        private ImageView iv_icon;
        private TextView tv_desc, tv_account, tv_count, tv_date;

        public TxViewHolder(View itemView) {
            super(itemView);

            iv_icon = (ImageView) itemView.findViewById(R.id.item_tx_history_icon);
            tv_desc = (TextView) itemView.findViewById(R.id.item_tx_history_txdesc);
            tv_account = (TextView) itemView.findViewById(R.id.item_tx_history_account);
            tv_count = (TextView) itemView.findViewById(R.id.item_tx_history_count);
            tv_date = (TextView) itemView.findViewById(R.id.item_tx_history_date);

        }
    }

    public int getDrawableResId(int type, int bankCode) {
        switch (type) {
            case 0:
                // return "打车银行";
                return R.mipmap.ic_bank_abc;
            case 1:
                // return "支付宝";
                return R.mipmap.ic_bank_alipay;
            case 2:
                // return "微信";
                return R.mipmap.ic_bank_abc;
            case 3:
                // return "信用卡";
                return R.mipmap.ic_bank_credit;
            case 4:
                // return "储蓄卡";
                // return R.drawable.ic_bank_abc;
                switch (bankCode) {
                    case 1:
                        // 中国工商银行
                        return R.mipmap.ic_bank_icbc;
                    case 2:
                        // 中国建设银行
                        return R.mipmap.ic_bank_ccb;
                    case 3:
                        // 中国银行
                        return R.mipmap.ic_bank_cb;
                    case 4:
                        // 中国农业银行
                        return R.mipmap.ic_bank_abc;
                    case 5:
                        // 中国交通银行
                        return R.mipmap.ic_bank_jiaotong;
                    case 6:
                        // 招商银行
                        return R.mipmap.ic_bank_zhaohang;
                    case 7:
                        // 中国中信银行
                    case 8:
                        // 上海浦东发展银行
                    case 9:
                        // 兴业银行
                    case 10:
                        // 中国民生银行
                    case 11:
                        // 中国光大银行
                    case 12:
                        // 平安银行
                        return R.mipmap.ic_bank_pingan;
                }
            case 5:
                // return "其他";
                return R.mipmap.ic_bank_abc;
        }

        return R.mipmap.ic_bank_abc;
    }

    public String getTypeName(int type) {
        switch (type) {
            case 0:
                return "打车钱包";
            case 1:
                return "支付宝";
            case 2:
                return "微信";
            case 3:
                return "信用卡";
            case 4:
                return "银行卡";
            case 5:
                return "其他";
        }
        return "其他";
    }
}
